<?php
namespace app\index\controller;

use Think\Exception;
use app\Common\lib\Util;
use app\Common\lib\Redis;
use app\Common\lib\redis\Predis;

class Login
{
    public  function login(){

//     print_r($_GET);
     $phone_num=$_GET['phone_num'];
     $code=$_GET['code'];

     if(empty($phone_num)||empty($code)){

        return Util::show(config('code.error'),'photo or code error','');
     }
     //redis code
        try{
           $rediscode=Predis::getInstance()->get(Redis::smsKey($phone_num));
        }catch(\Exception $e){
           echo $e->getMessage();
        }
     echo $rediscode;
     if($rediscode==$code){
         $data=[
             'user'=>$phone_num,
             'srcKey'=>md5(Redis::userKey($phone_num)),
             'time'=>time(),
             'is_login'=>true
         ];
        Predis::getInstance()->set(Redis::userKey($phone_num),$data);

        return Util::show(config('code.success'),'login success','');
     }else{
         return Util::show(config('code.error'),'login fail','');
     }

    }
}
